#include "editarchwidget.h"

EditArchWidget::EditArchWidget(ImageManager *imgmngr, ImageModel *imgmodel,
                               ScriptModel *scriptmodel,QWidget *parent) :
    QWidget(parent)
{
    m_arch = 0;

    QVBoxLayout *main_layout = new QVBoxLayout;
    this->setLayout(main_layout);

    QHBoxLayout *name_layout = new QHBoxLayout;

    QLabel *label = new QLabel(tr("Name:"));
    name_layout->addWidget(label);
    line = new QLineEdit();
    name_layout->addWidget(line);

    main_layout->addLayout(name_layout);

    QTabWidget *tab_widget = new QTabWidget();

    cmptab = new ComponentsTab(0, imgmngr, imgmodel);
    trigtab = new TriggersTab(0,scriptmodel);
    attrtab = new AttributesTab(0);

    tab_widget->addTab(cmptab,"Components");
    tab_widget->addTab(trigtab,"Triggers");
    tab_widget->addTab(attrtab,"Attributes");

    main_layout->addWidget(tab_widget);

    connect(line, SIGNAL(textEdited(QString)),
             this, SLOT(UpdateName(const QString&)));
}

void EditArchWidget::setArchtype(AED_Archtype* arch){
    m_arch = arch;
    if(arch){
        this->setEnabled(true);
        line->setText(arch->GetName());
    }else{
        this->setEnabled(false);
        line->setText("");
    }
    cmptab->setArchtype(arch);
    trigtab->setArchtype(arch);
    attrtab->setArchtype(arch);

}

void EditArchWidget::UpdateName(const QString &name){
    m_arch->SetName(name);
    emit nameChanged();
}

void EditArchWidget::UpdateArchtype(){
    setArchtype(m_arch);
}
